package com.enlorenz.core.engine.manager;

import com.enlorenz.common.util.ReflectionUtils;
import com.enlorenz.core.base.IObjectSeqInitializing;
import com.enlorenz.core.engine.IEngine;

/**
 * 可以启动多个线程
 * @author lcb
 */
public class MultiThreadManager implements IObjectSeqInitializing{
	//线程数量
	private int threadNum;
	//线程模板
	private IEngine engineModel;
	//线程管理
	private EngineManager engineManager;
	

	public void setThreadNum(int threadNum) {
		this.threadNum = threadNum;
	}

	public void setEngineModel(IEngine engineModel) {
		this.engineModel = engineModel;
	}

	public void setEngineManager(EngineManager engineManager) {
		this.engineManager = engineManager;
	}

	@Override
	public void objectSeqInit() throws Exception {
		for(int i=0;i<threadNum;i++){
			IEngine copy=(IEngine)engineModel.getClass().newInstance();
			ReflectionUtils.copyPrivField(copy, engineModel);
			copy.setName(copy.getName()+"-"+i);
			engineManager.getEngines().add(copy);
		}
	}
	
}
